<template>
  <div class="custom-layout">
    <custom-navbar/>
    <div class="main-content">
      <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="娱乐项目名称" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入娱乐项目名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="每小时价钱" prop="price">
            <el-input
              v-model="queryParams.price"
              placeholder="请输入每小时价钱"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['gameType:gameType:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['gameType:gameType:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['gameType:gameType:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['gameType:gameType:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="gameTypeList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="id" align="center" prop="id" />
          <el-table-column label="娱乐项目名称" align="center" prop="name" />
          <el-table-column label="每小时价钱" align="center" prop="price" />
          <el-table-column label="创建者" align="center" prop="createUser" />
          <el-table-column label="更新者" align="center" prop="updateUser" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['gameType:gameType:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['gameType:gameType:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 添加或修改娱乐类型管理对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="娱乐项目名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入娱乐项目名称" />
            </el-form-item>
            <el-form-item label="每小时价钱" prop="price">
              <el-input v-model="form.price" placeholder="请输入每小时价钱" />
            </el-form-item>
            <el-form-item label="创建者" prop="createUser">
              <el-input v-model="form.createUser" placeholder="请输入创建者" />
            </el-form-item>
            <el-form-item label="更新者" prop="updateUser">
              <el-input v-model="form.updateUser" placeholder="请输入更新者" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>

</template>

<script>
import { listGameType, getGameType, delGameType, addGameType, updateGameType } from "@/api/gameType/gameType"
import CustomNavbar from "@/components/CustomNavbar";

export default {
  name: "GameType",
  components: {CustomNavbar},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 娱乐类型管理表格数据
      gameTypeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        price: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "娱乐项目名称不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "每小时价钱不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询娱乐类型管理列表 */
    getList() {
      this.loading = true
      listGameType(this.queryParams).then(response => {
        this.gameTypeList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        price: null,
        createTime: null,
        updateTime: null,
        createUser: null,
        updateUser: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加娱乐类型管理"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getGameType(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改娱乐类型管理"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGameType(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addGameType(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除娱乐类型管理编号为"' + ids + '"的数据项？').then(function() {
        return delGameType(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('gameType/gameType/export', {
        ...this.queryParams
      }, `gameType_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style >
/* 使用与首页一致的配色方案 */
.main-content {
  position: absolute;
  top: 0; /* 强制贴顶 */
  left: 260px; /* 等于导航栏宽度 */
  width: calc(100% - 260px);
  height: 100vh;
  overflow-y: auto;

  background: white;
  z-index: 10; /* 确保在导航栏上方 */
}
:root {
  --primary-100: #8B5FBF;
  --primary-200: #61398F;
  --primary-300: #FFFFFF;
  --accent-100: #D6C6E1;
  --accent-200: #9A73B5;
  --text-100: #4A4A4A;
  --text-200: #878787;
  --bg-100: #F5F3F7;
  --bg-200: #E9E4ED;
  --bg-300: #FFFFFF;
}

/* 表单容器样式 */
.el-form {
  background: var(--bg-300);
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(139, 95, 191, 0.08);
  border: 1px solid var(--bg-200);
}

/* 表单标题样式 */
.el-form-item__label {
  color: var(--primary-200);
  font-weight: 600;
  font-size: 14px;
  padding-right: 15px;
}

/* 输入框样式 */
.el-input__inner, .el-date-editor.el-input__inner {
  height: 40px;
  line-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--bg-200);
  background-color: var(--bg-300);
  transition: all 0.3s ease;
  color: var(--text-100);
}

.el-input__inner:focus, .el-date-editor.el-input__inner:focus {
  border-color: var(--primary-100);
  box-shadow: 0 0 0 2px rgba(139, 95, 191, 0.2);
}

/* 日期选择器样式 */
.el-date-editor .el-input__prefix,
.el-date-editor .el-input__suffix {
  color: var(--primary-100);
}

/* 按钮样式 */
.el-button {
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.el-button--primary {
  background: linear-gradient(135deg, var(--primary-100), var(--primary-200));
  border: none;
  color: var(--primary-300);
}

.el-button--primary:hover {
  background: linear-gradient(135deg, var(--primary-200), var(--primary-100));
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(139, 95, 191, 0.3);
}

.el-button--default {
  border: 1px solid var(--primary-100);
  color: var(--primary-100);
  background: var(--bg-300);
}

.el-button--default:hover {
  background: var(--primary-100);
  color: var(--primary-300);
}

/* 表单项间距 */
.el-form-item {
  margin-bottom: 22px;
}

/* 搜索表单特殊样式 */
.el-form--inline .el-form-item {
  margin-right: 15px;
  margin-bottom: 15px;
}

/* 表格操作按钮样式 */
.el-button--text {
  color: var(--primary-100);
  font-weight: 500;
}

.el-button--text:hover {
  color: var(--primary-200);
}

/* 对话框表单样式 */
.el-dialog__body .el-form {
  padding: 10px 20px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .el-form--inline .el-form-item {
    display: block;
    margin-right: 0;
    width: 100%;
  }

  .el-form-item__content {
    width: 100%;
  }

  .el-input, .el-date-editor {
    width: 100% !important;
  }
}

/* 添加动画效果 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.el-form-item {
  animation: fadeIn 0.3s ease forwards;
}

/* 为不同表单项添加延迟动画 */
.el-form-item:nth-child(1) { animation-delay: 0.1s; }
.el-form-item:nth-child(2) { animation-delay: 0.2s; }
.el-form-item:nth-child(3) { animation-delay: 0.3s; }
.el-form-item:nth-child(4) { animation-delay: 0.4s; }
.el-form-item:nth-child(5) { animation-delay: 0.5s; }
</style>
